package org.example.dao;

import jakarta.transaction.Transactional;
import org.example.entity.DeliveryAddress;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface IDeliveryAddressRepository extends JpaRepository<DeliveryAddress, Integer> {
    public DeliveryAddress findByDaId(Integer daId);

    public List<DeliveryAddress> findAllByUserId(String userId);


//.save(返回对象)方法不用写, 但是delete(返回void)需要写
    @Transactional //加了这个注解之后, 就可以顺利删除
    public void deleteByDaId(Integer daId);

    @Modifying  //只有update 需要加@query, delete都不需要
    @Query("update DeliveryAddress d " + //这里这个标红,但是不影响运行
            "set d.contactName=?5, " +
            "d.contactSex=?4" +
            ",d.contactTel=?3," +
            "d.address=?2 " +
            "where  d.daId=?1")
    public void updateByDaIdFromEntity(Integer daId,
                                                  String address,
                                                  String contactTel,
                                                  Integer contactSex,
                                                  String contactName);



}
